package DAO;

import Bean.Order;
import Bean.Status;

import java.util.List;

/**
 * @author jianjun
 * @Describe
 * @creat 2022-01-01-17:21
 */
public class OrderDAOImpl extends BaseDAO implements OrderDAO {
    @Override
    public int saveOrder(Order order) {
        String sql = "insert into t_order(`order_id`,`create_time`,`total_money`,`status`,`user_id`) value(?,?,?,?,?)";
        return updata(sql, order.getOrder_id(), order.getCreate_time(), order.getTotal_money(), order.getStatus(), order.getUser_id());
    }

    @Override
    public List<Order> queryOrders() {
        String sql = "select `order_id`,`create_time`,`total_money`,`status`,`user_id` from t_order";
        return queryForList(Order.class, sql);
    }

    @Override
    public int changeOrderStatus(String order_id, Integer status) {
        String sql = "update t_order set`status`=? where order_id = ?";
        return updata(sql, status, order_id);
    }


    @Override
    public List<Order> queryOrdersByUserId(Integer userId) {
        String sql = "select * from t_order where user_id = ?";
        return queryForList(Order.class, sql, userId);
    }
}
